package leetcode.动态规划;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

class Solution {
    private boolean [][] memo;
    public boolean canPartition(int[] nums) {
        if (nums.length == 0) return false;
        int sum = 0;
        for (int i = 0; i < nums.length; i++) {
            sum += nums[i];
        }
        if (sum % 2 != 0) return false;
        int c = sum /= 2;
        int n = nums.length;
        memo = new boolean[n][c + 1];
        for (int i = 0; i <= c; i++) {
            memo[0][i] = (i >= nums[0]);
        }
        for (int i = 1; i < n; i++) {
            for (int j = 0; j <= c; j++) {
                if (j >= nums[i]) {
                    memo[i][j] =
                            memo[i - 1][j] || memo[i - 1][j - nums[i]];
                } else {
                    memo[i][j] = memo[i - 1][j];
                }
            }
        }
        return memo[n - 1][c];


    }


    public static void main(String[] args) {
//        boolean rob = new Solution().canPartition(new int[]{1, 2, 5});
//        System.out.println(rob);
        System.out.println('2'-'0');


    }
}